# 最终运行的入口类
# 负责创建案例中所需的对象，调用其函数
# 员工管理
# 员工入职
# 员工离职
# 员工调薪
# 员工查询
# 类
import json
import os

from ClassManager import Manager


def register(manager):
    with open("manager.json", "w", encoding="utf-8") as file:
        json.dump(manager.__dict__, file)
    print("注册成功")


def login(username, password):
    if os.path.exists("manager.json"):
        with open("manager.json", "r", encoding="utf-8") as file:
            data = json.load(file)
            if username == data["username"] and password == data["password"]:
                return True
            else:
                print("用户名或密码错误")
                return False
    else:
        print("请先注册")


if __name__ == '__main__':
    print("1.注册")
    print("2.登录")
    inp = int(input("请选择："))
    username = input("请输入用户名")
    password = input("请输入密码")
    manager = Manager(username, password)
    if inp == 1:
        register(manager)
    elif inp == 2:
        flag = login(username, password)
        if flag:
            manager.menu()

